 <div class="main_fr_mic" style="margin-bottom:10px;">
          <i class="glyphicon glyphicon-home"></i>
          <a href="admin/index">首页</a><span>></span>
          <a >系统管理</a><span>></span>
          <a class="active">字典管理</a>
 </div>
		<div id="interfaceList" class="main_fr_down over">
		 <div class="main_fr_search over mb10">
			  <div class="good_top2"><span>字典分类</span></div>
                   <div class="zTreeDemoBackground  main_fr_search_cx col-md-5" >
	                   	<input id ="tdid" type="hidden"/>
						<a href="javaScript:update(0);" class="btn btn-default">新增字典分类</a>
						
						<!-- <ul id="treeDemo" class="ztree"></ul> -->
						<div style="height:500px; overflow:auto">
						<table class="table table-bordered table-hover">
							<thead  class="table_heaer">
								<tr class="text-center">
									<th>编号</th>
									<th>code</th>
									<th>名称</th>
									<th>操作</th> 
								</tr>
							</thead>
							<tbody id="projectTable">
							</tbody>
						</table>
						</div>
					</div>
					<div class="zTreeDemoBackground  main_fr_search_cx col-md-6" style="margin-left: 30px;">
	                   	<input id ="tdid" type="hidden"/>
						<a href="javaScript:update2(0);" class="btn btn-default">新增一级字典值</a>
						<div style="height:500px; overflow:auto">
						<table class="table table-bordered table-hover">
							<thead  class="table_heaer">
								<tr class="text-center">
									<th>编号</th>
									<th>字典值</th>
									<th>状态</th>
									<th>操作</th> 
								</tr>
							</thead>
							<tbody id="projectTable2">
							</tbody>
						</table>
						</div>
					</div>
			  </div>
		</div>
<div class="hide addTreeNodeDiv">
<br>
	<form class="form-horizontal">
		<input id ="codeId" type="hidden" name="codeId"/>
		<div class="form-group col-md-12" id="newNode">
			<label class="col-sm-3  col-md-2 control-label">code值</label>
			<div class="col-sm-9 col-md-10">
				<input type="text" class="form-control" id="code" placeholder="请输code值" name="newNode">
			</div>
		</div>
		<div class="form-group col-md-12">
			<label class="col-sm-3  col-md-2 control-label">字典名称</label>
			<div class="col-sm-9 col-md-10">
				<input type="text" class="form-control" id="des" placeholder="请输字典名称" name="newNodeName">
			</div>
		</div>
	</form>
</div>
<div class="hide addTreeNodeDiv2">
<br>
	<form class="form-horizontal">
		<input id ="dict_id" type="hidden" name="dict_id"/>
		<input id ="parent_id" type="hidden" name="parent_id"/>
		<input id ="type_id" type="hidden" name="type_id"/>
		<div class="form-group col-md-12">
			<label class="col-sm-3  col-md-2 control-label">字典值</label>
			<div class="col-sm-9 col-md-10">
				<input type="text" class="form-control" id="content" placeholder="请输字典值" name="content">
			</div>
		</div>
		<div class="form-group hide" id="dict_status">
			<label for="exampleInputEmail2" class="col-sm-2 control-label">状态</label>
			<div class="col-sm-9">
			<select id="status" name="status" class="form-control" style="width:200px;">
              		<option value="1">启用</option>
              		<option value="0">禁用</option>
              	</select>
			</div>
		</div>
	</form>
</div>
<script src="assets/plugins/zTree_v3/js/jquery.ztree.core-3.5.js"></script>
<script src="assets/plugins/zTree_v3/js/jquery.ztree.excheck-3.5.js"></script>
<script src="assets/plugins/zTree_v3/js/jquery.ztree.exedit-3.5.js"></script>
<!-- //zTree_v3 -->
<link rel="stylesheet" href="assets/plugins/zTree_v3/css/metroStyle/metroStyle.css" type="text/css">
<link rel="stylesheet" href="assets/plugins/zTree_v3/css/zTreeStyle/zTreeStyle.css" type="text/css">
<script>
$.validator.setDefaults({
    submitHandler: function() {
    	 $.post('menu/update', $("#addForm").serialize(), function(data){
    		if(data.code==0){
    			layer.msg("保存成功！");
    			layer.close(index);
    		}else{
    			layer.msg("保存失败！");
    			return false;
    		}
    	}) 
    }
});
$().ready(function() {
    $("#addForm").validate();
    typeList();
});
function typeList() {
	$.post("dictionary/typeList?ttid="+Math.random(),function(data){
		if(data.code == 0){
			var dataStr = "";
			$.each(data.content, function(i, v) {
				dataStr += '<tr>';
				dataStr += '<td>' + v.id + '</td>';
				dataStr += '<td>' + v.code + '</td>';
				dataStr += '<td>' + v.des + '</td>';
				dataStr += '<td>';
					@@if (ac(session.userId, 'figure/update')){
						dataStr += '<a href="javaScript:update(' + v.id + ');" class="btn btn-default">' + '编辑' + '</a>';
					@@}
					dataStr += '<a id=type_'+v.id+' href="javaScript:info(' + v.id + ');" class="typec btn btn-default">' + '查看  >' + '</a>';
				dataStr += '</td>'; 
				dataStr += '</tr>';
			});
			$("#projectTable").html(dataStr);
			 
		}else{
			layer.msg('获取字典值列表失败！');
		}
	});
}
function update(id) {
	var tit = "新增字典分类";
	if(id != 0){
		tit = "修改字典分类";
		$.post("dictionary/getInfo",{id:id},function(data){
			if(data.code==0){
				for (var key in data.content){
					$("#"+key).val(data.content[key]);
				}
				$("#codeId").val(data.content["id"]);
			}else{
				layer.msg("获取信息失败！");
				return false;
			}
		})
		$("#newNode").addClass("hide");
	}else{
		$("input[name='newNodeName']").val('');
		$("input[name='newNode']").val('');
		$("#newNode").removeClass("hide");
	} 
	$(".addTreeNodeDiv").removeClass("hide");
 	layer.open({
		type : 1,
		area: '25%',
		offset: '40%',
		shift: 1,
		title : tit,
		content : $(".addTreeNodeDiv"),
		btn: ['确定', '取消'],
		yes: function(index, layero) {
			var codeId =$("input[name='codeId']").val();
			var newNodeName =$("input[name='newNodeName']").val();
			var newNode =$("input[name='newNode']").val();
			if(newNodeName==''){
				layer.msg('请输入字典分类名称');
				return false;
			}
			if(newNode==''){
				layer.msg('请输入code值');
				return false;
			}
			$.post("dictionary/updateType?ttid="+Math.random(),{"codeId":codeId,'newNodeName':newNodeName,"newNode":newNode}, function(data){
				if(data.code==3){
					layer.msg(data.content);
					return false;
				}else{
					layer.msg('操作成功！');
					typeList();
				}
			 });
			layer.close(index);
		},
		cancel: function(index) {
			layer.msg("已关闭");
		}
	})
};
function info(id){
	$("input[name='type_id']").val(id);
	$(".typec").css("color","black");
	$("#type_"+id).css("color","red");
	
	$.post("dictionary/list?ttid="+Math.random(),{"type_id":id},function(data){
		if(data.code == 0){
			var dataStr = "";
			$.each(data.content, function(i, v) {
				dataStr += '<tr>';
				dataStr += '<td>' + v.id + '</td>';
				dataStr += '<td>' + v.content + '</td>';
				if(v.status==0){
					dataStr += '<td>禁用</td>';
				}else if(v.status==1){
					dataStr += '<td>启用</td>';
				}else{dataStr += '<td></td>';}
				dataStr += '<td>';
					@@if (ac(session.userId, 'figure/update')){
						dataStr += '<a href="javaScript:update2(' + v.id + ');" class="btn btn-default">' + '编辑' + '</a>';
					@@}
					if(1==1){
						dataStr += '<a href="javaScript:upRow(' + v.id + ',' + v.type_id + ');" class="btn btn-default" title="下移"><i class="glyphicon glyphicon-arrow-down"></i></a>';
					}
					if(1==1){
						dataStr += '<a href="javaScript:downRow(' + v.id + ',' + v.type_id + ');"class="btn btn-default" title="上移"><i class="glyphicon glyphicon-arrow-up"></i></a>';
					}
				dataStr += '</td>'; 
				dataStr += '</tr>';
			});
			$("#projectTable2").html(dataStr);
			 
		}else{
			$("#projectTable2").html("");
			layer.msg('获取的字典值列表为空！');
		}
	});
}
function update2(id){
	var type_id =$("input[name='type_id']").val();
	if(type_id==''){
		layer.msg('请先选择字典分类');
		return ;
	}
	var tit = "新增字典值";
	if(id != 0){
		$("#dict_status").removeClass("hide");
		var tit = "修改字典值";
		$.post("dictionary/getInfo2",{id:id,type_id:type_id},function(data){
			if(data.code==0){
				for (var key in data.content){
					$("#"+key).val(data.content[key]);
				}
				$("#dict_id").val(data.content["id"]);
			}else{
				layer.msg("获取信息失败！");
				return false;
			}
		})
	}else{
		$("input[name='parent_id']").val('');
		$("input[name='content']").val('');
		$("input[name='dict_id']").val('');
		$("#dict_status").addClass("hide");
	}
	$(".addTreeNodeDiv2").removeClass("hide");
	layer.open({
		type : 1,
		area: '25%',
		offset: '40%',
		shift: 1,
		title : tit,
		content : $(".addTreeNodeDiv2"),
		btn: ['确定', '取消'],
		yes: function(index, layero) {
			var dict_id =$("input[name='dict_id']").val();
			var parent_id =$("input[name='parent_id']").val();
			var type_id =$("input[name='type_id']").val();
			var content =$("input[name='content']").val();
			var status =$("[name='status']").val();
			if(content==''){
				layer.msg('请输入字典值名称');
				return false;
			}
			if(type_id==''){
				layer.msg('请先选择字典分类');
				return false;
			}
			$.post("dictionary/update?ttid="+Math.random(),{"id":dict_id,'parent_id':parent_id,"type_id":type_id,"status":status,"content":content}, function(data){
				if(data.code==3){
					layer.msg(data.content);
					return false;
				}else{
					layer.msg('操作成功！');
					info(type_id);
				}
			 });
			layer.close(index);
		},
		cancel: function(index) {
			layer.msg("已关闭");
		}
	})
};
function upRow(id,type){
	$.post("dictionary/upRow",{id:id,type:type}, function(data){
		if (data.code == 0) {
			info(type);
		} else {
			layer.msg("当前字典值已经是最后一位！");
		}
   	});
}
function downRow(id,type){
	$.post("dictionary/downRow",{id:id,type:type},function(data){
		if (data.code == 0) {
			info(type);
		} else {
			layer.msg("当前字典值已经在第一位！");
		}
   	});
}
</script>